import { ActionKey } from "@/action/ActionKey";
import { controller } from "./Controller";

export enum InfoLevel {
  'DEBUG' = 'DEBUG',
  'INFO' = 'INFO',
  'WARN' = 'WARN',
  'ERROR' = 'ERROR',
}

export const ContextMenuConfig = {
  [ActionKey.ExportInstance]: {
    label: 'export',
    value: ActionKey.ExportInstance,
    icon: "",
    children: [
      // { label: 'ins_exis', value: 'exportToExisted', method: 'exportToExisted', disabled: false, },
      { label: 'ins_new', value: ActionKey.ExportInstance, disabled: false, }
    ],
    disabled: false,
  },
  [ActionKey.RemoveValue]: {
    label: 'remove_value',
    value: ActionKey.RemoveValue,
    icon: "",
    children: [],
    disabled: false,
  },
  [ActionKey.AddValue]: {
    label: 'add_value',
    value: 'addValue',
    icon: "",
    children: [],
    disabled: false,
  },
  [ActionKey.OpenTimeSeriesChart]: {
    label: 'start_diagram',
    value: ActionKey.OpenTimeSeriesChart,
    icon: "",
    children: [],
    disabled: false,
  },
  [ActionKey.ExportInteraction]: {
    label: 'export_interaction',
    value: ActionKey.ExportInteraction,
    icon: "",
    children: [],
    disabled: false,
  },
  [ActionKey.SelectOnTree]: {
    label: 'select_on_tree',
    value: ActionKey.SelectOnTree,
    icon: "",
    children: [],
    disabled: false,
  }
};

export type SceneData = {
  icon?: string
  isSelected?: boolean
  id: string
  instanceId: string
  name: string
  type: string
  parent: string
  children: SceneData[]
  expand?: boolean
  modelVo?: any // modelInfo
  state: SceneState
}

export type ConstraintInfo = {
  valid: boolean // 是否满足
  tempId: string // 需求编号
  tempText: string // 需求内容
  requirementId: string // 需求id
}

export class VariableData {
  icon?: string
  expand?: boolean
  isSelected?: boolean
  hasChildren: boolean
  constraintMessage: string | null
  export: boolean
  expression: string | null
  modelId: string
  multiple: boolean
  ownerSceneId: string
  sceneIds: null | string[]
  status: string
  value: any
  valueId: string
  valueList: string[] | null
  valueType: string
  variableType: string
  children?: VariableData[]
  modelVo?: any // modelInfo
  name?: string
  disabled?: boolean
  valueShow?: boolean
  mindex?: number
  isRoot?: boolean
  parentValueId?: string
  constraintInfoList?: ConstraintInfo[] = []
  /** 验证需求 */
  validationReq?: { name: string, value: string, modelId: string, icon: string, valid: boolean }[]
  /** 需求内容 */
  reqContent?: { name: string, value: string, valid: boolean }[]

  [key: string]: any;

  constructor(option: VariableData) {
    this.modelVo = option.modelVo;
    this.icon = option.icon;
    this.constraintMessage = option.constraintMessage;
    this.sceneIds = option.sceneIds;
    this.export = option.export;
    this.multiple = option.multiple;
    this.hasChildren = option.hasChildren;
    this.expression = option.expression;
    this.valueList = option.valueList;
    this.modelId = option.modelId;
    this.ownerSceneId = option.ownerSceneId;
    this.status = option.status;
    this.value = option.value;
    this.valueId = option.valueId;
    this.valueType = option.valueType;
    this.variableType = option.variableType;
    this.expand = option.expand;
    this.children = option.children;
    this.name = option.name;
    this.disabled = option.disabled;
    this.mindex = option.mindex;
    this.isRoot = option.isRoot;
    this.validationReq = option.validationReq;
    this.reqContent = option.reqContent;
  }
}

export enum SimulateStatusType {
  none = "none", // can init
  initing = "initing",
  ready = "ready", // can start
  running = "running",
  stop = "stop", // means:: stepone
  finish = "finish",
  pause = "pause",
  checking = "checking"
}

export enum BtnValue {
  SIMULATION_INIT = 'initSimulation',
  SIMULATION_START = 'startSimulation',
  SIMULATION_PAUSE = 'pauseSimulation',
  SIMULATION_CONTINUE = 'continueSimulation',
  STEP_ONE = 'stepOne',
  SIMULATION_FINISH = 'finishSimulation',
  DIAGRAM_AUTOCHANGE = 'diagramautochange',
}

export const diagramAutoChangeBtn = {
  icon: "statics/icons/simulation/simulation-auto-switch.svg",
  tooltip: "auto_d_switch",
  value: BtnValue.DIAGRAM_AUTOCHANGE,
  isDisabled: false,
};

export type HeaderBtns = {
  icon: string
  tooltip: string
  value: BtnValue
  isVisible: boolean
  isDisabled: boolean
}

export const headerBtns = [
  {
    icon: "statics/icons/simulation/simulation-icon1.svg",
    tooltip: "ini",
    value: BtnValue.SIMULATION_INIT,
    isVisible: true,
    isDisabled: false,
    // get isVisible() {
    //   return true;
    // },
    // get isDisabled() {
    //   return controller.toolbarService.status !== SimulateStatusType.none;
    // },
  },
  {
    icon: "statics/icons/simulation/simulation-icon2.svg",
    tooltip: "_start",
    value: BtnValue.SIMULATION_START,
    isVisible: true,
    isDisabled: false,
  },
  {
    icon: "statics/icons/simulation/simulation-icon5.svg",
    tooltip: "_puase",
    value: BtnValue.SIMULATION_PAUSE,
    isVisible: true,
    isDisabled: false,
  },
  {
    icon: "statics/icons/simulation/simulation-icon6.svg",
    tooltip: "_continue",
    value: BtnValue.SIMULATION_CONTINUE,
    isVisible: true,
    isDisabled: false,
  },
  {
    icon: "statics/icons/simulation/simulation-icon3.svg",
    tooltip: "_step",
    value: BtnValue.STEP_ONE,
    isVisible: true,
    isDisabled: false,
  },
  {
    icon: "statics/icons/simulation/simulation-icon4.svg",
    tooltip: "_stop",
    value: BtnValue.SIMULATION_FINISH,
    isVisible: true,
    isDisabled: false,
  }
];

export type SignalType = {
  id: number,
  name: string
}

export type LogRecord = {
  id?: string,
  time?: string,
  context?: string,
  level: InfoLevel,
  code?: number,
  message: string
};

export enum SocketUpdateVariableMsgType {
  "REMOVE" = "REMOVE",
  "INSERT" = "INSERT",
  "UPDATE" = "UPDATE",
}

export type SocketUpdateVariableMsg = {
  sceneId: string,
  type: SocketUpdateVariableMsgType,
  valueId: string
  objectId?: string
}

export type UIFrameRenderData = {
  objectId: string,
  properties: {
    propertyId: string,
    valueType: string,
    values: string[]
  }[]
}

export type ConstraintVariationNotice = {
  constraintMessage: string
  id: string
  status: 'white' | 'green' | 'red'
  valueId: string
  constraintInfoList?: ConstraintInfo[]
}

export class SimulationConfig {
  currentNodeIsSimulationConfig = false; // 当前节点是否是仿真配置节点
  clockMode: 'RealTime' | 'Internal' = 'RealTime';
  isRelativeTime = true;
  clockRatio = 1;
  startTime = 0;
  autoStart = false
  autostartActiveObjects = true
  fumlDecision = false
  silent = false
}

export enum SceneState {
  READY = 'READY', // 已就绪
  RUNNING = 'RUNNING', // 已启动
  SUSPEND = 'SUSPEND', // 已暂停
  STOP = 'STOP' // 已结束
}

export const ConsoleDotColor = {
  [InfoLevel.DEBUG]: '#21A1C7',
  [InfoLevel.INFO]: '#52C41A',
  [InfoLevel.WARN]: '#E1AD00',
  [InfoLevel.ERROR]: '#D02A26',
};

export const SceneStateColor = {
  [SceneState.READY]: '#52C41A',
  [SceneState.RUNNING]: '#1890FF',
  [SceneState.SUSPEND]: '#E8A113',
  [SceneState.STOP]: '#7E7E7E'
};

export const SceneStateLabel = {
  [SceneState.READY]: '已就绪',
  [SceneState.RUNNING]: '已启动',
  [SceneState.SUSPEND]: '已暂停',
  [SceneState.STOP]: '已结束'
};